package com.example.shoppingdemo.nslcommodity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.IResult.CommodityRs;
import com.example.shoppingdemo.nslcommodity.IResult.ICommodityResult;
import com.example.shoppingdemo.nslcommodity.adapter.ReturnsAdapter;
import com.example.shoppingdemo.nslcommodity.javabean.ReturnsModel;

import java.util.ArrayList;
import java.util.List;

public class ReturnsActivity extends AppCompatActivity {
    private List<ReturnsModel>returnsModelList;
    private ICommodityResult commodityResult;
    private ReturnsAdapter adapter;
    private LinearLayout linearLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_returns);
        commodityResult=new CommodityRs(this);
        initView();
    }
    private void initView(){
        ImageView returnicon=findViewById(R.id.image_returns_back);
        returnicon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        RecyclerView returns=findViewById(R.id.order_form_returns);
        linearLayout=findViewById(R.id.layout_order_form_returns);
        returns.setLayoutManager(new LinearLayoutManager(this));
        returnsModelList=new ArrayList<>();
        adapter=new ReturnsAdapter(this);
        adapter.setReturnsModels(returnsModelList);
        adapter.setParticulars(new ReturnsAdapter.onReturnsParticulars() {
            @Override
            public void onReturnsResult(int position) {
                Intent intent=new Intent(ReturnsActivity.this,ReturnsDemo.class);
                intent.putExtra("id",returnsModelList.get(position).getId());
                startActivity(intent);
            }
        });
        returns.setAdapter(adapter);
        commodityResult.onReturns(new CommodityRs.onReturnsResponse() {
            @Override
            public void onReturnsList(List<ReturnsModel> returnsModels) {
                returnsModelList.clear();
                returnsModelList.addAll(returnsModels);
                if (returnsModels.size()==0){
                    linearLayout.setVisibility(View.VISIBLE);
                }else {
                    adapter.setReturnsModels(returnsModelList);
                    adapter.notifyDataSetChanged();
                }
            }
        });
    }
}